﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace TTCaller
{
    public enum BoxStatusItem { GPRS, GPS, ACC, Server, Box };
    public partial class BoxStatus : UserControl
    {
        public BoxStatus()
        {
            InitializeComponent();
            this.label_Server.BackColor = Color.FromArgb(StoreData.getInstance().BackColor);
            this.label_Server.ForeColor = Color.FromArgb(StoreData.getInstance().ForeColor);

     //       this.panel_Status.BackColor = this.label_GPRS.BackColor;
            this.timer_Checker.Enabled = true;

            this.button1.Visible = StoreData.getInstance().IsDebug;

        }


        bool m_bServer;


        public bool ServerStatus { get { return m_bServer; } }


        private DateTime dtServer = System.DateTime.Now.Add(new TimeSpan(0, 5, 30));

        private void resetdtServer()
        {
            dtServer = System.DateTime.Now.Add(new TimeSpan(0, 5, 30));
        }
        public void setServerStatus(bool arg_bServer)
        {
            resetdtServer();
            m_bServer = arg_bServer;
            updateStatus();
        }


        public void updateStatus()
        {

            try
            {
                if (m_bServer)
                {
                    this.label_Server.Text = "連線";
                }
                else
                {
                    this.label_Server.Text = "斷線";

                }

            }
            catch (Exception ex)
            {
            }
        }

        private void timer_Checker_Tick(object sender, EventArgs e)
        {
            try
            {
                if (dtServer < System.DateTime.Now)
                {
                    setServerStatus(false);
                    resetdtServer();
                }
                int nB = DeviceManager.getInstance().getPowerExt();
                this.label_Battery.Text =nB.ToString();
                if (nB < StoreData.getInstance().BatteryWarnValue)
                    this.label_Battery.ForeColor = Color.Red;
                else
                    this.label_Battery.ForeColor = this.label_Server.ForeColor;

                 
            }
            catch (Exception ex)
            {
                LogManager.getInstance().Log("Error", ex);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form_Main.Main.button_Log_Click(null, null);
        }
    }
}
